Fix to compile for C libraries with no flockfile
authorРуслан Ижбулатов <lrn1986@gmail.com>
Wed, 30 Dec 2015 18:05:05 +0000 (18:05 +0000)
committerРуслан Ижбулатов <lrn1986@gmail.com>
Wed, 30 Dec 2015 21:57:29 +0000 (21:57 +0000)
Also use MS variant of flockfile, if available
(requires MSVCRT compatible with MSVCR90 or newer).

configure.ac
gtk/gtkimmodule.c

index 89d00d792e8a301e5d19e3476446fedb61aba368..fb27eaac666b6228fe922644e93fb32dae875797 100644 (file)
@@ -413,7 +413,7 @@ AC_SUBST(DISABLE_ON_QUARTZ)
 AC_CHECK_LIB([rt], [shm_open], [SHM_LIBS="-lrt"], [SHM_LIBS=""])
 AC_SUBST(SHM_LIBS)
 
-AC_CHECK_FUNCS(posix_fallocate)
+AC_CHECK_FUNCS(posix_fallocate flockfile _lock_file)
 
 if test "x$enable_broadway_backend" = xyes; then
   GDK_BACKENDS="$GDK_BACKENDS broadway"
index 405d87626fc1eaf5d8a562e1a1531b1d07665d7c..47e6348ebe084398ac46e6e1c86abf4a6b26a8e4 100644 (file)
 
 #include "deprecated/gtkrc.h"
 
+/* We need to call getc() a lot in a loop. This is suboptimal,
+ * as getc() does thread locking on the FILE it is given.
+ * To optimize that, lock the file first, then call getc(),
+ * then unlock.
+ * If locking functions are not present in libc, fall back
+ * to the suboptimal getc().
+ */
+#if !defined(HAVE_FLOCKFILE) && !defined(HAVE__LOCK_FILE)
+#  define flockfile(f) (void)1
+#  define funlockfile(f) (void)1
+#  define getc_unlocked(f) getc(f)
+#elif !defined(HAVE_FLOCKFILE) && defined(HAVE__LOCK_FILE)
+#  define flockfile(f) _lock_file(f)
+#  define funlockfile(f) _unlock_file(f)
+#  define getc_unlocked(f) _getc_nolock(f)
+#endif
+
 #define SIMPLE_ID "gtk-im-context-simple"
 #define NONE_ID   "gtk-im-context-none"